package com.awesomeproject;

import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.widget.ImageView;
import android.widget.TextView;


import butterknife.BindView;



public class ShowFirstActivity extends MyBaseActivity {
    @BindView(R.id.showAds) ImageView img_ads;
    @BindView(R.id.textTime) TextView text_time;
    private int time=4;
    private Handler myHandler;
    CountThread countThread;

    @Override
    public int getViewId() {
        return R.layout.activity_showfirst;
    }

    @Override
    protected void initVariables() {
        myHandler = new Handler();
        countThread = new CountThread();
        countThread.start();
    }

    @Override
    protected void initView(Bundle savedInstanceState) {

    }

    @Override
    protected void loadData() {

    }

    private class CountThread extends Thread{
        public void run()
        {
            while(time!=0){
                myHandler.post(runnableUi);
                if (time==2)
                {
                    myHandler.post(runaddImage);
                }
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e){
                    e.printStackTrace();
                }
            }
            Intent intent=new Intent(   ShowFirstActivity.this,LoginActivity.class);
            startActivity(intent);
            ShowFirstActivity.this.finish();
        }
    }
    Runnable runnableUi = new Runnable(){
        @Override
        public void run(){
            time--;
            text_time.setText("倒计时"+time);

        }
    };
    Runnable runaddImage=new Runnable() {
        @Override
        public void run() {
            img_ads.setImageResource(R.mipmap.showfirst);
        }
    };

}
